﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
   

    [SerializeField]
    Rigidbody2D myRigidbody2D;
    public float speed;
    public float upspeed;
    private int jumpcount = 0;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector2 move = myRigidbody2D.velocity;
        move.x = 0;
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            move.x -= speed;
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            move.x += speed;
        }
        if (Input.GetKeyDown(KeyCode.Space) && jumpcount<2)
        {

            move.y += upspeed;
            
            jumpcount++;
        }
        myRigidbody2D.velocity = move;
    }
        private void OnCollisionEnter2D(Collision2D collision)
        {
        if (collision.collider.transform.position.y < this.transform.position.y)
        
            jumpcount = 0;
        }

}
